<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "tbl_user".
 *
 * @property integer $id
 * @property string $username
 * @property string $password
 * @property string $email
 * @property string $profile
 *
 * @property TblPost[] $tblPosts
 */
class TblUser_reg_form extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'tbl_user';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['username', 'password', 'email'], 'required'],
            [['profile'], 'string'],
        	[['username'],'unique',"message"=>'用户名被占用'],
        	[['email'],'email'],
            [['username', 'password', 'email'], 'string', 'max' => 128]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'username' => '用户名',
            'password' => '密码',
            'email' => '邮箱',
            'profile' => '简介',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getTblPosts()
    {
        return $this->hasMany(TblPost::className(), ['author_id' => 'id']);
    }
    
    
    public function signup()
    {
    	if ($this->validate()) {
    		//$user = new User();
    		//$user->username = $this->username;
    	//$user->setPassword($this->password);
    		//$user->create_time = time();
    		
    		$this->save();
    		echo $this->username;
    		echo $this->id;
    		if ($this->id) {
    			
    			echo 'dfsafasdfsa';
    			//;
    			
    		 $user = 	User::findByUsername($this->username);
    		 
    		 //$user = self::find()->where("username='".$this->username."'")->one();
    		  echo "ccc";
    		  print_R($user);
    		 // exit;
    			return $user;
    		}
    	}
    
    	return null;
    }
}
